//stack.c


#include <stdio.h>
#include <stdlib.h>

typedef struct stack
{
    int *s;
    int stacksize;
    int top;
}stack;

void init_stack(stack *s)
{
    s->stacksize = 100;
    s->s =(int*)malloc(sizeof(int) * s->stacksize);
    s->top = -1;
}
int stack_empty(stack *s)
{
    return ((-1 == s->top) ? 1 : 0);
}

void push(stack *s,int x)
{
    if(s->top == s->stacksize)
        printf("overflow.\n");
    else
    {
        s->top++;
        s->s[s->top] = x;
    }
}
int pop(stack *s)
{
    if( stack_empty(s) )
        printf("underflow.\n");
    else
    {
        s->top--;
		return s->s[s->top+1];
    }
}


int main()
{
    stack s;
    init_stack(&s);
	//
    push(&s,19);
    push(&s,23);
    push(&s,34);
    push(&s,76);
    push(&s,65);

	printf("%d\n", pop(&s));
	printf("%d\n", pop(&s));
	printf("%d\n", pop(&s));
	printf("%d\n", pop(&s));
	printf("%d\n", pop(&s));
	printf("%d\n", pop(&s));

}